<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>资源位分类列表</title>
</head>
<body>

<!--{include file='comm/naviBanner.tpl'}-->

<div class="container">

    <!--{include file='comm/menu.tpl'}-->

    <div class="comm_crub">
        <span class="now_crub">资源位分类列表</span>
    </div>

    <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form id="search_form" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    <span>
                                        <select id="parent_id" name="parent_id">
                                            <!--{foreach from=$source_array item=val}-->
                                                <option value="<!--{$val.id}-->"><!--{$val.title}--></option>
                                            <!--{/foreach}-->
                                        </select>
                                    </span>
                                    <span><input type="button" value="查询" class="btn" onclick="source.search();" /></span>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>


</div>

<script type="text/javascript">
    $("#flex").flexigrid({
        url:"/invokingAjax-backend/content/source.ajax?operFlg=1",
        dataType: "json",
        colModel : [
            {display: "操作", width : 200, align: "center"},
            {display: "分类号", name : "source_category_id", width : 100, sortable : true},
            {display: "分类标题", width : 260},
            {display: "分类别名", width : 100},
            {display: "描述", width : 360}
        ],
        buttons : [
            {name: "添加", bclass: "add", onpress : "source.add"},
            {separator: true},
            {name: "删除", bclass: "delete", onpress : "source.deleteCategory"}
        ],
        sortname: "source_category_id",
        sortorder: "desc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true,
        autoload: <!--{if $source_array}-->true<!--{else}-->false<!--{/if}-->,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    var source = {

        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },

        add: function() {
            E.open("/quanliadmin/app/content/source.pscript?operFlg=2");
        },

        edit: function(category_id) {
            E.open("/quanliadmin/app/content/source.pscript?operFlg=3&category_id=" + category_id);
        },

        load: function() {
            $("#flex").flexReload();
        },

        source_add: function(category_id) {
            E.open("/quanliadmin/app/content/source.pscript?operFlg=4&category_id=" + category_id, "", {height: 600,width: 1024, top: 50, left: 150});
        },

        publish: function(parent_id, category_id) {
            E.open("/quanliadmin/app/content/source.pscript?operFlg=8&parent_id=" + parent_id + "&category_id=" + category_id, "", {height: 600,width: 1024, top: 50, left: 150})
        },

        deleteCategory: function() {
            this.delete_str = "";
            var str = "";
            $.each($("#flex").find("tr"), function(k, v) {
                if ($(v).hasClass("trSelected")) {
                    if ($(v).find("input:hidden").val() == 1) {
                        str = "<b>删除顶级资源位分类，同时会删除所有下级资源位分类及资源位</b><br><br>";
                        source.delete_str = "_" + $(v).attr("id").replace("row", "");
                        return false;
                    } else {
                        str = "<b>删除资源位分类，同时会删除分类下所有资源位</b><br><br>";
                        source.delete_str += "_" + $(v).attr("id").replace("row", "");
                    }
                }
            });
            if (this.delete_str == "")
                E.alert("请选择删除资源位分类");
            else
                E.confirm(str + "您确认要删除选中的资源位分类吗？", "source.deleteConfirm");
        },

        deleteConfirm: function() {
            this.delete_str = this.delete_str.substr(1);
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/content/source.ajax?operFlg=10&delete_str=" + source.delete_str,
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "E.refresh");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        }

    };
</script>

</body>
</html>